import {useAuthStore} from '@/store';
import {localStg} from '@/utils';
import {remoteFetchUpdateToken} from '../api';

/**
 * 刷新token
 * @param
 */
export async function refreshTokenHandler() {
	const {resetAuthStore} = useAuthStore();
	const {data} = await remoteFetchUpdateToken(localStg.get('refreshToken') || '');
	if (data) {
		localStg.set('token', data.accessToken);
		localStg.set('refreshToken', data.refreshToken);
		return data;
	}

	resetAuthStore();
	return null;
}
